//package com.liuwei.spring.cloud.configuration;
//
//import com.baomidou.mybatisplus.autoconfigure.SpringBootVFS;
//import com.baomidou.mybatisplus.core.config.GlobalConfig;
//import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
//import com.baomidou.mybatisplus.core.incrementer.IKeyGenerator;
//import com.baomidou.mybatisplus.core.injector.ISqlInjector;
//import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
//import org.apache.ibatis.session.SqlSessionFactory;
//import org.springframework.beans.factory.InitializingBean;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.util.ObjectUtils;
//import org.springframework.util.StringUtils;
//
//import javax.sql.DataSource;
//
///**
// * @author : MybatisConfiguration
// * @version V1.0
// * @date: 2023/12/27 9:40 PM
// * @Description: TODO
// */
//@Configuration
//public class MybatisConfiguration implements InitializingBean {
//    @Bean
//    public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
//        MybatisSqlSessionFactoryBean factory = new MybatisSqlSessionFactoryBean();
//        factory.setDataSource(dataSource);
//        factory.setVfs(SpringBootVFS.class);
//        if (StringUtils.hasText(this.properties.getConfigLocation())) {
//            factory.setConfigLocation(this.resourceLoader.getResource(this.properties.getConfigLocation()));
//        }
//
//        this.applyConfiguration(factory);
//        if (this.properties.getConfigurationProperties() != null) {
//            factory.setConfigurationProperties(this.properties.getConfigurationProperties());
//        }
//
//        if (!ObjectUtils.isEmpty(this.interceptors)) {
//            factory.setPlugins(this.interceptors);
//        }
//
//        if (this.databaseIdProvider != null) {
//            factory.setDatabaseIdProvider(this.databaseIdProvider);
//        }
//
//        if (StringUtils.hasLength(this.properties.getTypeAliasesPackage())) {
//            factory.setTypeAliasesPackage(this.properties.getTypeAliasesPackage());
//        }
//
//        if (this.properties.getTypeAliasesSuperType() != null) {
//            factory.setTypeAliasesSuperType(this.properties.getTypeAliasesSuperType());
//        }
//
//        if (StringUtils.hasLength(this.properties.getTypeHandlersPackage())) {
//            factory.setTypeHandlersPackage(this.properties.getTypeHandlersPackage());
//        }
//
//        if (!ObjectUtils.isEmpty(this.properties.resolveMapperLocations())) {
//            factory.setMapperLocations(this.properties.resolveMapperLocations());
//        }
//
//        if (StringUtils.hasLength(this.properties.getTypeEnumsPackage())) {
//            factory.setTypeEnumsPackage(this.properties.getTypeEnumsPackage());
//        }
//
//        GlobalConfig globalConfig = this.properties.getGlobalConfig();
//        if (this.applicationContext.getBeanNamesForType(MetaObjectHandler.class, false, false).length > 0) {
//            MetaObjectHandler metaObjectHandler = (MetaObjectHandler)this.applicationContext.getBean(MetaObjectHandler.class);
//            globalConfig.setMetaObjectHandler(metaObjectHandler);
//        }
//
//        if (this.applicationContext.getBeanNamesForType(IKeyGenerator.class, false, false).length > 0) {
//            IKeyGenerator keyGenerator = (IKeyGenerator)this.applicationContext.getBean(IKeyGenerator.class);
//            globalConfig.getDbConfig().setKeyGenerator(keyGenerator);
//        }
//
//        if (this.applicationContext.getBeanNamesForType(ISqlInjector.class, false, false).length > 0) {
//            ISqlInjector iSqlInjector = (ISqlInjector)this.applicationContext.getBean(ISqlInjector.class);
//            globalConfig.setSqlInjector(iSqlInjector);
//        }
//
//        factory.setGlobalConfig(globalConfig);
//        return factory.getObject();
//    }
//
//    @Override
//    public void afterPropertiesSet() throws Exception {
//
//    }
//}
